package com.hushan.elevator.websocket;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class WebSocketProtocol {
    private String type;
    private String version = "1.0";
    private int id;
    private String uuid;
    private String body;
    private static int messageId = 0; // 静态变量，用于消息序号

    // 转换为JSON格式的方法
    public String toJson() {
        return String.format(
                "{\"type\": \"%s\", \"version\": \"%s\", \"id\": %d, \"body\": %s}",
                type != null ? type : "",
                version,
                id, body);
    }

    public WebSocketProtocol(int id, String type, String version, String body) {
        this.id = id;
        this.type = type;
        this.version = version;
        this.body = body;
    }
}
